/**
 * 
 * 患者诊疗
 */
import React from 'react';
import { Button, Tooltip } from 'antd';
import { Util } from 'tools/index';
import { $http } from 'containers/config/https';
import ShowComponentModal from './ShowComponentModal';
import '../style/index.less';

const appointment = require('../../../assets/images/img/appointment.png');
const history = require('../../../assets/images/img/history.png');
const hospital = require('../../../assets/images/img/hospital.png');
const inspect = require('../../../assets/images/img/inspect.png');
const patho = require('../../../assets/images/img/patho.png');
const records = require('../../../assets/images/img/records.png');
const textReport = require('../../../assets/images/img/textReport.png');
const infectious = require('../../../assets/images/img/infectious.png');
const diagnosis = require('../../../assets/images/img/diagnosis.png');
const information = require('../../../assets/images/img/information.png');
const productionBook = require('../../../assets/images/img/productionBook.png');//产检本
const resultTarget = require('../../../assets/images/img/resultTarget.png');//检验结果第三方
const doctorAdviceFind = require('../../../assets/images/img/doctorAdviceFind.png');//医嘱查询

export default class PatientsClinicalTabPane extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        var patientData = JSON.parse(sessionStorage.getItem('patientData'));
        this.state = {
            total: 0,
            page: 1,
            pageSize: 10,
            current: 3,
            isShowOutPatientModal: true,
            isShowTriageSystemModal: true,
            userData: userData,
            patientData: patientData,
            openIdLocalId: "000005",
            password: "56f9c6690d1edc97e7a55de96c4b3a1488fe0fe46748b00c1fa15b36",
            service: "http://120.79.237.79:8086/jumper-cs-nt/nt/personInfo/toPersonIndex",
            manualId: "37150200200000131",
        }
    }

    componentWillUnmount() {
        // 组件销毁前将静止让setState修改state的状态
        this.setState = (state, callback) => { return; }
    }

    componentDidMount() {
        this.setState({
            current: this.props.current,
        })
        this.loadData()
    }

    loadData() {
        var params = {
            params: [{
                GroupDr: this.state.userData.groupID,
                LocDr: this.state.userData.locID,
                Type: 3
            }]
        }
        $http.post('urlS', this, {
            code: '3001',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({ doctorData: res.result });
                } else {
                    this.setState({ doctorData: [] });
                }
            }
        })
    }

    openWindowBySubTab(data) {
        var { openWindowBySubTab } = this.props;
        openWindowBySubTab && openWindowBySubTab(data)
    }

    hashROuter(code) {
        // this.props.history.push('./03050002/01')
        var { hashROuter } = this.props;
        hashROuter && hashROuter(code);
    }

    saveDiagnosisMsg(id) {
        this.setState({
            current: id
        })
    }

    change(e) {
        this.setState({
            current: e,
            isShowOutPatientModal: true
        })
    }

    //隐藏弹出框
    hideModal(name) {
        this.setState({
            [name]: false,//将所有参数置为false
        });
    }

    //公共动态弹框
    showComponentModal(data) {
        if (data.code == "03050047") {
            this.setState({
                isShowComponentModal: false,
                dataSource: {}
            }, () => {
                let data = {
                    params: [{
                        admID: sessionStorage.patientData ? JSON.parse(sessionStorage.patientData).admID : "",
                        // admID:48,
                    }]
                }
                $http.post('urlS', this, {
                    code: '03050149',
                    data: data,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                            this.setState({
                                manualId: res.result.manualId
                            }, () => {
                                const { openIdLocalId, password, service, manualId } = this.state
                                service.replace(/\&/g, "%26")
                                let url = "120.79.237.79:8081/cas/login?auto=true&openIdLocalId=" + openIdLocalId + "&password=" + password + "&service=" + service + "?manualId=" + manualId + "&treeType=1&enterType="
                                window.open("http://" + url, "_blank", "toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, ");
                            })
                        } else {

                        }
                    }
                })

            })
        } else {
            this.setState({
                isShowComponentModal: true,
                dataSource: data
            })
        }

    }

    render() {
        var { doctorData } = this.state;
        var componentOption = []
        //webpack配置有问题，现在只能这样写死图片
        //动态渲染右侧组件
        doctorData && doctorData.map((item, index) => {
            var img = ''
            if (item.code == '03050010') {
                img = records
            } else if (item.code == '03050030') {
                img = inspect
            } else if (item.code == '03050031') {
                img = patho
            } else if (item.code == '03050034') {
                img = textReport
            } else if (item.code == '03050011') {
                img = appointment
            } else if (item.code == '03050032') {
                img = infectious
            } else if (item.code == '03050012') {
                img = hospital
            } else if (item.code == '02050033') {
                img = history
            } else if (item.code == '03050044') {
                img = doctorAdviceFind
            } else if (item.code == '03050045') {
                img = textReport
            } else if (item.code == '03050036') {
                img = diagnosis
            } else if (item.code == '03050038') {
                img = information
            } else if (item.code == '03050046') {
                img = resultTarget
            } else if (item.code == '03050047') {
                img = productionBook
            } else if (item.code == '03050050') {
                img = productionBook
            } else if (item.code == '03050061') {
                img = productionBook
            } else if (item.code == '03050063') {
                img = appointment
            }
            componentOption.push(
                <Tooltip title={this.state.userData.language == 'EN' ? (item.ENDesc ? item.ENDesc : item.title) : item.title}
                    placement='left'>
                    <Button className='common-btn-style' key={index} style={{ height: 70 }}
                        disabled={Util.isEmpty(this.props.patientData) ? true : false}
                        onClick={this.showComponentModal.bind(this, item)}>
                        <div><img style={{ marginTop: 10 }} src={img} /></div>
                        <span style={{ padding: '5px 0', width: "70px", textOverflow: "ellipsis", overflow: "hidden" }}>
                            {this.state.userData.language == 'EN' ? (item.ENDesc ? item.ENDesc : item.title) : item.title}</span></Button></Tooltip>)
        })
        return <div className='patient-step' style={{ height: this.props.height ? this.props.height : 'calc(100% - 80px)' }}>
            {/**公共组件弹框 */}
            <ShowComponentModal isShow={this.state.isShowComponentModal}
                dataSource={this.state.dataSource}
                onHide={this.hideModal.bind(this, 'isShowComponentModal')} />
            <div style={{ height: '100%' }}>
                {/* <div style={{ width: '5%', float: 'left', paddingTop: 10 }} className='patient-btn-group'>
                    <Tooltip title={Util.isEmpty(this.props.patientData) ? '暂无病人信息，无法点击' : ''} placement="left">
                        <ButtonGroup>
                            {componentOption}
                        </ButtonGroup>
                    </Tooltip>
                </div>
                <div style={{ float: 'right', width: '94.6%', height: '100%' }}> */}
                {this.props.loadStepCompent}
                {/* </div> */}
            </div>
        </div>
    }

}